package com.liucxu.zimuzu.Presenter.Impl;

import com.liucxu.zimuzu.Base.ResponseSubscriber;
import com.liucxu.zimuzu.Model.Bean.ChannelResourceBean;
import com.liucxu.zimuzu.Model.IChannelResourceModel;
import com.liucxu.zimuzu.Model.Impl.ChannelResourceModelImpl;
import com.liucxu.zimuzu.Presenter.IChannelPresenter;
import com.liucxu.zimuzu.Utils.TransformUtils;
import com.liucxu.zimuzu.View.IView.IChannelView;

import java.util.HashMap;

/**
 * 获取Channel的Presenter实现类
 * Created by liukanshan on 2016/12/25.
 */

public class ChannelPresenterImpl implements IChannelPresenter {

    private IChannelView mChannelView;
    private IChannelResourceModel mChannelResourceModelImpl;

    public ChannelPresenterImpl(IChannelView view){
        mChannelView=view;
        mChannelResourceModelImpl=new ChannelResourceModelImpl();
    }

    @Override
    public void getFetchList(HashMap<String, String> values) {
        mChannelView.showLoading();
        mChannelResourceModelImpl.getFetchList(values).compose(TransformUtils.<ChannelResourceBean>defaultSchedulers()).subscribe(new ResponseSubscriber<ChannelResourceBean>() {
            @Override
            public void onSuccess(ChannelResourceBean bean) {
                if(bean!=null){
                    mChannelView.setChannel(bean);
                }
            }

            @Override
            public void onFailure(Throwable error) {
                mChannelView.showError(error.getMessage());
            }
        });
    }
}
